package com.cmxh.mycloudnotes.controller;

import com.cmxh.mycloudnotes.Service.UserService;
import com.cmxh.mycloudnotes.pojo.UpdPwd;
import com.cmxh.mycloudnotes.pojo.User;
import com.cmxh.mycloudnotes.util.Code01;
import com.cmxh.mycloudnotes.util.Result01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/zhuce")
    public Result01 save(@RequestBody User xx) {
        int i = userService.saveUser( xx );
        if (i > 0) {
            return new Result01( Code01.SAVE_OK, "注册成功" );
        } else {
            return new Result01( Code01.SAVE_ERR, "注册失败" );
        }
    }

    @RequestMapping("/login")
    public Result01 login(@RequestBody User xx) {
        return userService.login( xx );
    }


    @RequestMapping("/updateZt")
    public Result01 updateZt(@RequestBody UpdPwd xx) {


        Result01 i = userService.updateZt( xx );

        if (i != null) {
            return new Result01( Code01.UPDATE_OK, "修改成功" );
        } else {
            return new Result01( Code01.UPDATE_ERR, "修改失败" );
        }


    }

    @RequestMapping("/updatePwd")
    public Result01 updatePwd(@RequestBody User xx) {
        int i = userService.updatePwd( xx );
        if (i > 0) {
            return new Result01( Code01.UPDATE_OK, "修改成功" );
        } else {
            return new Result01( Code01.UPDATE_ERR, "修改失败" );
        }
    }
    @RequestMapping("/updatePic")
    public Result01 updatePic(@RequestBody User xx) {
        int i = userService.updatePic( xx );
        if (i > 0) {
            return new Result01( Code01.UPDATE_OK, "修改成功" );
        } else {
            return new Result01( Code01.UPDATE_ERR, "修改失败" );
        }
    }

}
